home *** CD-ROM | disk | FTP | other *** search
- unit PageDefn;
- {********************************************************************}
- {** Unit : Pagedefn **}
- {** **}
- {** Description : This unit contains the dialog proc and callback **}
- {** for the created PropertyPage. This is done **}
- {** using yukky "Raw" API functions. **}
- {** **}
- {** Version History : **}
- {** **}
- {** A0.01 Initial version started 27/10/96 **}
- {** **}
- {** Copyright ⌐1996 Warren F. Young **}
- {********************************************************************}
- interface
- uses
- Windows, { Standard Units }
- CommCtrl,
- SysUtils,
- Messages,
-
- Global,{ Application Specific Units }
- Resource;
-
-
- {********************************************************************}
- {** public function definitions **}
-
- function PropExtCallback(Wnd: HWnd; Msg: Integer; PPSP: PPropSheetPageA):Integer stdcall;
- function PropExtDlgProc(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint):longBool; stdcall;
-
- {********************************************************************}
- implementation
-
- type
- PPropInfo = ^TPropInfo;
- TPropInfo = record
- PropPage : TPropSheetPage;
- end;
-
-
- {********************************************************************}
- {** Function : WindowFromID **}
- {** **}
- {** Description : This function returns the window handle of a **}
- {** control with the given ID. Requires parent window handle. **}
- {********************************************************************}
- function WindowFromID( Parent : HWnd; ID : integer):hWnd;
- var
- hWndControl : hWnd;
- begin
- hWndControl:=GetTopWindow(Parent); { get the top one }
- repeat
- if GetWindowLong(hWndcontrol,GWL_ID)=ID then break; { just quit out }
- hWndControl:=GetNextWindow(hWndControl,GW_HWNDNEXT);
- until hWndControl=0;{last window}
- Result:=hWndControl;
- end;
-
-
- {********************************************************************}
- {** Function : OnCreate **}
- {** **}
- {** Description : This function handles WM_InitDialog messages **}
- {********************************************************************}
- function OnCreate(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool;
- var
- Info : PPropInfo;
- MWWFile : integer;
- FileName : string;
- FileIDStr : array[0..10] of char;
- Title,Composer: array[0..255] of char;
- S : String;
- Key1, Key2 : byte;
- begin
- {** Create Info structure to store useful variables **}
- GetMem(Info,Sizeof(TPropInfo)); { allocate memory }
- Info^.PropPage:=PPropSheetPage(LParam)^; { copy page into }
- SetWindowLong(Dialog,GWL_USERDATA,longint(Info)); { store it in window }
- FillChar(FileIDStr, sizeof(FileIDStr), 0);
- FillChar(Title, sizeof(Title), 0);
- FillChar(Composer, sizeof(Composer), 0);
-
- {** Try reading in the file **}
- { assignfile(MWWFile,PChar(Info^.PropPage.lParam));
- reset(MWWFile,1); {}
- MWWFile := FileOpen(PChar(Info^.PropPage.lParam), fmOpenRead);
- try
- try
- FileRead(MWWFile,FileIDStr,sizeof(FileIDStr)); { read in file id string }
- S := StrPas(@FileIDStr);
- If copy(S, 1, 11) <> 'music works' then {not a real *.mww file}
- begin
- Title := 'unknown - file not valid';
- Composer := 'unknown - file not valid';
- end
- else begin
- FileSeek(MWWFile,21,0); { Offset to byte number 22 }
- FileRead(MWWFile,Title,sizeof(Title)); {read in title}
- FileRead(MWWFile,Composer,sizeof(Composer)); {read in composer}
- FileSeek(MWWFile, $5FB, 0);
- FileRead(MWWFile, Key1, 1);
- FileSeek(MWWFile, $5FD, 0);
- FileRead(MWWFile, Key2, 1);
- end;
- except
- On EInOutError do { nothing };
- end;
- finally
- FileClose(MWWFile);
- end; { try finally }
-
- Filename := {StrPas}(PChar(Info^.PropPage.lParam));
- Filename := ExtractFileName(Filename);
- { SendMessage(WindowFromID(Dialog,id_Filename),WM_SetText,0,UINT(Info^.PropPage.lParam));{}
- SendMessage(WindowFromID(Dialog,id_Filename),WM_SetText,0,UINT(@FileName[1]));
- SendMessage(WindowFromID(Dialog,id_SongTitle),WM_SetText,0,UINT(@Title));
- SendMessage(WindowFromID(Dialog,id_Composer),WM_SetText,0,UINT(@Composer));
- If key1 = 1 then
- begin { music key is with sharps }
- Case key2 of
- 1 : {key = G } S := 'G major';
- 2 : {key = D } S := 'D major';
- 3 : {key = A } S := 'A major';
- 4 : {key = E } S := 'E major';
- 5 : {key = G } S := 'B major';
- 6 : {key = G } S := 'F# major';
- 7 : {key = G } S := 'C# major';
- else S := 'More than 7 or less than 1 sharps';
- end; { case }
- end else
- If key1 = 2 then
- begin { music key is with flats }
- Case key2 of
- 1 : {key = F } S := 'F major';
- 2 : {key = Bb} S := 'Bb major';
- 3 : {key = Eb} S := 'Eb major';
- 4 : {key = Ab} S := 'Ab major';
- 5 : {key = Db} S := 'Db major';
- 6 : {key = Gb} S := 'Gb major';
- 7 : {key = Cb} S := 'Cb major';
- else S := 'More than 7 or less than 1 flats';
- end; { case }
- end else
- If key1 = 0 then { key = C }
- S := 'C major'
- else S := 'unknown';
- SendMessage(WindowFromID(Dialog,id_MusicKey),WM_SetText,0,UINT(S));
- Result:=FALSE;
- end;
-
-
- {********************************************************************}
- {** Function : OnCommand **}
- {** **}
- {** Description : This function handles WM_Command messages **}
- {********************************************************************}
- function OnCommand(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool;
- var
- Info : PPropInfo;
- begin
- Info:=pointer(GetWindowLong(Dialog,GWL_USERDATA)); { get TPropInfo }
-
- case WParam of
-
- id_AboutBox :
- MessageBox( Dialog,'Properties of Music Works2 files'#13#10'Copyright (c) 1996 Warren F. Young'#13#10'Freeware',
- 'About',mb_OK OR mb_IconInformation);
- end;
-
- Result:=FALSE;
- end;
-
-
- {********************************************************************}
- {** Function : TPropInfo.OnNotify **}
- {** **}
- {** Description : This function handles WM_Notify messages **}
- {********************************************************************}
- function OnNotify(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool;
- begin
- case PNMHdr(lParam)^.code of
-
- PSN_APPLY : SetWindowLong(Dialog,DWL_MSGRESULT,longint(TRUE));
-
- PSN_KILLACTIVE : begin
- SetWindowLong(Dialog,DWL_MSGRESULT,longint(FALSE));
- Result:=TRUE;
- exit;
- end;
-
- PSN_RESET: begin
- SetWindowLong(Dialog,DWL_MSGRESULT,longint(FALSE));
- end;
-
- end;{of lParam case}
- Result:=FALSE;
- end;
-
- {********************************************************************}
- {** Function : PropExtDlgProc **}
- {** **}
- {** Description : This function is the dialog callback function **}
- {** for the property page and is responsible for all the UI funcs **}
- {********************************************************************}
- function PropExtDlgProc(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool; stdcall;
- begin
- case AMessage of
-
- WM_InitDialog : Result:=OnCreate(Dialog,AMessage,WParam,LParam);
-
- WM_Command : Result:=OnCommand(Dialog,AMessage,WParam,LParam);
-
- WM_Notify : Result:=OnNotify(Dialog,AMessage,WParam,LParam);
-
- else
- Result:=FALSE;
- end; {of case}
- end;
-
-
- {********************************************************************}
- {** Function : PropExtCallback **}
- {** **}
- {** Description : This function is the property page callback **
- {** which deals with the setup and removal of the page & stuff **}
- {********************************************************************}
- function PropExtCallback(Wnd: HWnd; Msg: Integer; PPSP: PPropSheetPageA): Integer; stdcall;
- var
- Info : PPropInfo;
- begin
- case Msg of
-
- PSPCB_Create : inc(RefThisDLL); {** make sure we don't get the rug pulled **}
- PSPCB_Release : begin
- Info:=pointer(GetWindowLong(Wnd,GWL_USERDATA));
- FreeMem(Info,sizeof(TPropInfo));
- FreeMem(pointer(PPSP.lParam),MAX_PATH);
- dec(RefThisDLL); {** make sure we can release the DLL **}
- end;
-
- end;
- Result:=1; { always allow creation }
- end;
-
-
- end.
- {********************************************************************}
-